package com.server.file.rabbitmq;

import cn.hutool.core.util.StrUtil;
import com.rabbitmq.client.Channel;
import com.server.commons.rabbitmq.constant.UploadFileRabbitMQConstant;
import com.server.file.service.UploadImageLogService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@Configuration
public class UploadFileRabbitMQ {

    @Resource
    private UploadImageLogService uploadImageLogService;

    /**
     * 接受添加日志操作
     * @author LXC
     * @date 2022/6/19 18:41
     */
    @RabbitListener(
            bindings = {
                    @QueueBinding(value = @Queue(value = UploadFileRabbitMQConstant.UPLOAD_IMAGE_QUEUE),
                            exchange = @Exchange(value = UploadFileRabbitMQConstant.UPLOAD_FILE_EXCHANGE),
                            key = {UploadFileRabbitMQConstant.UPLOAD_IMAGE_ROUTING_KEY})
            },
            concurrency = "1",ackMode = "MANUAL"
    )
    @RabbitHandler
    public void uploadImageLog(Channel channel, Message message) throws IOException {
        String str = StrUtil.str(message.getBody(), StandardCharsets.UTF_8);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();

        channel.basicAck(deliveryTag,false);
    }

}
